package rippleutils;

public class General1 {

	/**
	 * Clamp x so that it is in range specified by [min, max],
	 * using this formula:
	 * returnValue = x%modulus + min;
	 * @param min minimum of range (inclusive)
	 * @param max maximum of range (inclusive)
	 * @param x variable to clamp
	 * @return x clamped into range
	 */
	public static int wrapAroundClamp(int min, int max, int x) {
		
		int modulus = max - min + 1;
		return Math.abs(x) % modulus  + min;
	}

}
